package com.xiaoke.service.impl;

import com.xiaoke.entity.Collect;
import com.xiaoke.mapper.CollectMapper;
import com.xiaoke.service.CollectService;
import com.xiaoke.utils.SnowflakeIdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;
import java.util.Map;

@Service
public class CollectServiceImpl implements CollectService {
    @Autowired
    private CollectMapper collectMapper;
    @Autowired
    private SnowflakeIdWorker snowflakeIdWorker;
    @Override
    public Collect findByUserAndGoods(String userId, String goodsId) {
        return collectMapper.findByUserAndGoods(userId,goodsId);
    }

    @Override
    @Transactional(readOnly = false)
    public void delete(String id) {
        collectMapper.deleteByPrimaryKey(id);
    }

    @Override
    @Transactional(readOnly = false)
    public void insert(@RequestBody Collect collect) {
        collect.setId(String.valueOf(snowflakeIdWorker.nextId()));
        collectMapper.insert(collect);
    }

    @Override
    public List<Map<String, Object>> findByUser(String userId) {
        return collectMapper.findByUser(userId);
    }

}
